home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
Issue42
/
system
/
UCAnimatedIcon.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1999-01-03
|
3KB
|
101 lines
unit UCAnimatedIcon;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
UCAniIcon;
type
TUCAnimatedIcon = class(TCustomControl)
private
{ Private declarations }
fIcon: TAniIcon;
fAnimate: Boolean;
procedure SetIcon (Value: TAniIcon);
procedure SetAnimate (Value: Boolean);
procedure TimerTick (var Msg: TMessage); message wm_Timer;
protected
{ Protected declarations }
procedure Paint; override;
public
{ Public declarations }
constructor Create (AOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property TabOrder;
property TabStop;
property Visible;
property Color;
property ParentColor;
property Hint;
property Icon: TAniIcon read fIcon write SetIcon;
property Animate: Boolean read fAnimate write SetAnimate default False;
end;
procedure Register;
implementation
constructor TUCAnimatedIcon.Create (AOwner: TComponent);
begin
Inherited Create (AOwner);
fIcon := TAniIcon.Create;
Width := GetSystemMetrics (sm_cxIcon);
Height := GetSystemMetrics (sm_cyIcon);
end;
destructor TUCAnimatedIcon.Destroy;
begin
fIcon.Free;
Inherited Destroy;
end;
procedure TUCAnimatedIcon.SetIcon (Value: TAniIcon);
begin
fIcon.Assign (Value);
fIcon.BackgroundColor := Color;
end;
procedure TUCAnimatedIcon.SetAnimate (Value: Boolean);
begin
fAnimate := Value;
if fAnimate then SetTimer (Handle, 1, 50, Nil) else KillTimer (Handle, 1);
end;
procedure TUCAnimatedIcon.Paint;
var
R: TRect;
begin
if (not fAnimate) and (not fIcon.Empty) then begin
R := Rect (0, 0, fIcon.Width, fIcon.Height);
OffsetRect (R, (Width - fIcon.Width) div 2, (Height - fIcon.Height) div 2);
fIcon.Draw (Canvas, R);
end;
end;
procedure TUCAnimatedIcon.TimerTick (var Msg: TMessage);
var
R: TRect;
begin
if not fIcon.Empty then begin
fIcon.Animate;
R := Rect (0, 0, fIcon.Width, fIcon.Height);
OffsetRect (R, (Width - fIcon.Width) div 2, (Height - fIcon.Height) div 2);
fIcon.Draw (Canvas, R);
end;
end;
procedure Register;
begin
RegisterComponents('UnCommon', [TUCAnimatedIcon]);
end;
end.